package com.ruoyi.web.controller.laiqianba.addresssInfo;

import com.ruoyi.db.domain.AddressInfo;
import com.ruoyi.laiqianba.service.IAddressInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地址列表Controller
 * 
 * @author ruoyi
 * @date 2023-08-13
 */
@RestController
@RequestMapping("/addressInfo/addressInfo")
public class AddressInfoController extends BaseController
{
    @Autowired
    private IAddressInfoService addressInfoService;

    /**
     * 查询地址列表列表
     */
    @PreAuthorize("@ss.hasPermi('addressInfo:addressInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AddressInfo addressInfo)
    {
        List<AddressInfo> list = addressInfoService.selectAddressInfoList(addressInfo);
        return getDataTable(list);
    }

    /**
     * 导出地址列表列表
     */
    @PreAuthorize("@ss.hasPermi('addressInfo:addressInfo:export')")
    @Log(title = "地址列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AddressInfo addressInfo)
    {
        List<AddressInfo> list = addressInfoService.selectAddressInfoList(addressInfo);
        ExcelUtil<AddressInfo> util = new ExcelUtil<AddressInfo>(AddressInfo.class);
        util.exportExcel(response, list, "地址列表数据");
    }

    /**
     * 获取地址列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('addressInfo:addressInfo:query')")
    @GetMapping(value = "/{cityCode}")
    public AjaxResult getInfo(@PathVariable("cityCode") String cityCode)
    {
        return success(addressInfoService.selectAddressInfoByCityCode(cityCode));
    }

    /**
     * 新增地址列表
     */
    @PreAuthorize("@ss.hasPermi('addressInfo:addressInfo:add')")
    @Log(title = "地址列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddressInfo addressInfo)
    {
        return toAjax(addressInfoService.insertAddressInfo(addressInfo));
    }

    /**
     * 修改地址列表
     */
    @PreAuthorize("@ss.hasPermi('addressInfo:addressInfo:edit')")
    @Log(title = "地址列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AddressInfo addressInfo)
    {
        return toAjax(addressInfoService.updateAddressInfo(addressInfo));
    }

    /**
     * 删除地址列表
     */
    @PreAuthorize("@ss.hasPermi('addressInfo:addressInfo:remove')")
    @Log(title = "地址列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cityCodes}")
    public AjaxResult remove(@PathVariable String[] cityCodes)
    {
        return toAjax(addressInfoService.deleteAddressInfoByCityCodes(cityCodes));
    }
}
